﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using System.Data;
using System.Text;

namespace Interface.Rooms
{
    public partial class RoomDetails : System.Web.UI.Page
    {
        DataConnection dc = new DataConnection();
        DataValid dv = new DataValid();
        string stringDetail;

        protected void Page_Load(object sender, EventArgs e)
        {
            getQueryString();
        }

        private void getQueryString()
        {
            if (Request.QueryString["ID"] != null)
            {
                stringDetail = Request.QueryString["ID"].ToString();
                DetailBind(stringDetail);
            }
        }

        private void DetailBind(string roomId)
        {
            string sqlRoom = "Select * from Rooms where RoomID='" + roomId + "'";
            DataTable dt = dc.getData(sqlRoom);
            StringBuilder roomList = new StringBuilder();

            if (dt.Rows.Count > 0)
            {
                
                    DataRow row = dt.Rows[0];

                    string _houseId = row["HouseID"].ToString();
                    
                    string sqlAddress = "Select * from BoardingHouse where IdHouse = '" + _houseId + "'";
                    DataTable dt1 = dc.getData(sqlAddress);

                    string _address = null;
                    string _phone =null;
                    if (dt1.Rows.Count > 0)
                    {
                                    
                        DataRow row1 = dt1.Rows[0];
                        string _Street = row1["Street"].ToString();
                        string _Ward = row1["Ward"].ToString();
                        int _idDistrict = Convert.ToInt32(row1["District"]);
                        string strsql = "Select Name from District where  IdDistrict ='" + _idDistrict + "'";
                        string _dis = dc.getStringValue(strsql);


                        int _idCity = Convert.ToInt32(row1["City"]);
                        string strsql1 = "Select Name from City where  IdCity ='" + _idCity + "'";
                        string _city = dc.getStringValue(strsql1);

                        string _contact = Convert.ToString(row1["Contact"]);

                        _phone = _contact;
                        _address = _Street + ", p. " + _Ward +", "+ _dis + ", tp. " + _city;

                    }


                    string _idRoom = row["RoomID"].ToString();

                    string _nameOfRoom = row["Name"].ToString();

                    string _discription = row["Descript"].ToString();

                    //int _available = Convert.ToInt32(row["Available"]);
                    //string _tinhtrang = "Còn chổ";
                    //if (_available == 1)
                    //{
                    //    _tinhtrang = "Phòng đả đầy";

                    //}

                    string _area = row["Area"].ToString();

                    string _price = row["Price"].ToString();

                    int _maxperson = Convert.ToInt32(row["MaxPerson"]);

                    int _curoerson = Convert.ToInt32(row["CurPerson"]);

                    int internet = Convert.ToInt32(row["Internet"]);
                    string _internet = "có"; 
                    if (internet == 0)
                    {
                        _internet = "không";
                    }

                    string imgRoom = row["ImageSource"].ToString();
                    
                    string _imgRoom = "/Images/Room/" + imgRoom;

                    string _roomedit = "EditRoom.aspx?ID=" + _idRoom;

                    string _roomList = "RoomList.aspx?ID=" + _houseId;
                    
                roomList.AppendFormat(@"<div class='info-main'>Địa Chỉ: </div>
                                <div class='info-main-right'> {0}</div>
                                <div class='small-pace'></div>
                                <div class='info-main'>Phòng: </div>
                                <div class='info-main-right'>{1}</div>
                                <div class='small-pace'></div>
                                <div class='info-main'>Diện Tích: </div>
                                <div class='info-main-right'>
                                    {2} m
                                <sup>2</sup>
                                </div>
                                <div class='small-pace'></div>
                                <div class='small-pace'></div>
                                <div class='info-main'> Giá: </div>
                                <div class='info-main-right'> {3} VND/Tháng</div>
                                <div class='small-pace'></div>
                                <div class='info-main'>Số Người Tối Đa: </div>
                                <div class='info-main-right'>{4} người</div>
                                <div class='small-pace'></div>
                                <div class='info-main'>Số Người Đang Ở: </div>
                                <div class='info-main-right'>{5} người</div>
                                <div class='small-pace'></div>
                                <div class='info-main'>Internet: </div>
                                <div class='info-main-right'>{6} </div>
                                <div class='small-pace'></div>
                                <div class='info-main'>Liên Hệ: </div>
                                <div class='info-main-right'>{7}</div>
                                <div class='small-pace'></div>
                                <div class='HD-image-cover'>
                                    <div class='info-main'>Hình Ảnh: </div>
                                    <div class='HD-Image-box'>
                                    <img width='200' height='200' src={8}>
                                    </div>
                                </div>
                                <div class='small-pace'></div>
                                <div class='box-butotn'>
                                    <a href={9}>
                                    <img width='80' height='37' src='/Images/Icon/edit-button.png'>
                                    </a>
                                    
                                    <a href={10}>
                                    <img width='80' height='37' src='/Images/Icon/reset-button.png'>
                                    </a>
                                    
                                </div>
                                ", _address, _nameOfRoom, _area, _price, _maxperson, _curoerson, _internet, _phone, _imgRoom, _roomedit, _roomList);

                    lit.Text = roomList.ToString();


                
            }



        }
    }
}